

namespace Stee.CAP8.MessageBus.Interface.Interfaces
{
    using System;
    using Stee.CAP8.MessageBus.Interface.Delegates;
    using Stee.CAP8.MessageBus.Interface.Models;

    /// <summary>
    /// Subscriber interface
    /// </summary>
    public interface ISubscriber : IDisposable
    {
        #region Properties

        /// <summary>
        /// Gets the message topic
        /// </summary>
        TopicName TopicName { get; }

        /// <summary>
        /// Gets the subscriber group ID
        /// </summary>
        string GroupID { get; }

        /// <summary>
        /// Gets the subscriber client ID
        /// </summary>
        string ClientID { get; }

        /// <summary>
        /// Gets the flag indicating that subscriber is initialized and ready for reading messages
        /// </summary>
        bool IsInitialized { get; }

        /// <summary>
        /// Gets the flag indicating if subscriber is polling for new messages
        /// </summary>
        bool IsConnected { get; }

        /// <summary>
        /// Gets the flag indicating disposed state
        /// </summary>
        bool IsDisposed { get; }

        #endregion Properties


        /// <summary>
        /// Initializes the subscription
        /// </summary>
        /// <param name="topicName">Subscription topic</param>
        /// <param name="subscribedMessageHandler">Subscribed message handler</param>
        /// <param name="brokerErrorHandler">Broker error handler</param>
        /// <returns>Return TRUE if initialized else FALSE</returns>
        bool Initialize(TopicName topicName, HandleSubscribeMessage subscribedMessageHandler, HandleBrokerError brokerErrorHandler);

        /// <summary>
        /// Initializes the subscription
        /// </summary>
        /// <param name="topicName">Subscription topic</param>
        /// <param name="subscribedCommandHandler">Subscribed command handler</param>
        /// <param name="brokerErrorHandler">Broker error handler</param>
        /// <returns>Return TRUE if initialized else FALSE</returns>
        bool Initialize(TopicName topicName, HandleSubscribeCommand subscribedCommandHandler, HandleBrokerError brokerErrorHandler);

        /// <summary>
        /// Initializes the subscription
        /// </summary>
        /// <param name="topicName">Subscription topic</param>
        /// <param name="subscribedEventHandler">Subscribed event handler</param>
        /// <param name="brokerErrorHandler">Broker error handler</param>
        /// <returns>Return TRUE if initialized else FALSE</returns>
        bool Initialize(TopicName topicName, HandleSubscribeEvent subscribedEventHandler, HandleBrokerError brokerErrorHandler);

        /// <summary>
        /// Subscribe to configured topic
        /// </summary>
        void Subscribe();


        /// <summary>
        /// Commit message
        /// </summary>
        /// <param name="brokerMessage">Raw broker message returned from subscription</param>
        /// <returns>Return TRUE if committed els FALSE</returns>
        bool Commit(object brokerMessage);

        ////// Note: This 'commit' interface is simpler but not recommeded as this interface is used by other message brokers besides Kafka
        //bool Commit(string topic, int partition, long offset);
    }
}
